import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:light_image/config/const.dart';

class ComMomBar extends StatelessWidget implements PreferredSizeWidget {
  const ComMomBar({
    this.title = '',
    this.showShadow = false,
    this.rightDMActions,
    this.backgroundColor ,
    this.mainColor = Colors.amber,
    this.titleW,
    this.bottom,
    this.leadingImg = '',
    this.leadingW,
  });

  /**
   * 标题
   */
  final String title;

  /**
   * 显示阴影
   * 居中方式的
   */
  final bool showShadow;
  final List<Widget> rightDMActions;
  final Color backgroundColor;
  final Color mainColor;
  final Widget titleW;
  final Widget leadingW;
  final PreferredSizeWidget bottom;
  /**
   * 导航图片
   */
  final String leadingImg;

  @override
  Size get preferredSize => new Size(100, 50);

  Widget leading(BuildContext context) {
    final bool isShow = Navigator.canPop(context);

    if (isShow) {
      return new InkWell(
        child: new Container(
          width: 15,
          height: 28,
          child: leadingImg != ''
              ? new Image.asset(leadingImg)
              : new Icon(CupertinoIcons.back, color: mainColor),
        ),
        onTap: () {
          if (Navigator.canPop(context)) {
            FocusScope.of(context).requestFocus(new FocusNode());
            Navigator.pop(context);
          }
        },
      );
    } else {
      return null;
    }
  }
//static initAppBarColor(){
// var  backgroundColor=List();
// backgroundColor.add(backgroundColor);
// return backgroundColor;
//}
  @override
  Widget build(BuildContext context) {
    return showShadow
        ? new Container(
      decoration: BoxDecoration(
          border: Border(
              bottom: new BorderSide(
                  color: Colors.grey, width: showShadow ? 0.5 : 0.0))),
      child: new AppBar(
        title: titleW == null
            ? new Text(
          title,
          style: new TextStyle(
              color: mainColor,
              fontSize: 17.0,
              fontWeight: FontWeight.w500),
        )
            : titleW,
        backgroundColor: mainColor,
        elevation: 0.0,
        brightness: Brightness.dark,
        leading: leadingW ?? leading(context),
        centerTitle: true,
        actions: rightDMActions ?? [new Center()],
        bottom: bottom != null ? bottom : null,
      ),
    )
        :
    new Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
          colors: [
            Color.fromARGB(255,138,126,255), Color.fromARGB(255,120,168,255)
          ],
        ),
      ),
    child:
    new AppBar(
      title: titleW == null
          ? new Text(
        title,
        style: new TextStyle(
            color: mainColor,
            fontSize: 17.0,
            fontWeight: FontWeight.w500),
      )
          : titleW,
      backgroundColor: Colors.transparent,
      elevation: 0.0,
      brightness: Brightness.dark,
      leading: leadingW ?? leading(context),
      centerTitle: false,
      bottom: bottom != null ? bottom : null,
      actions: rightDMActions ?? [new Center()],
    ));
  }


//
//  @override
//  Widget build(BuildContext context) {
//    return showShadow
//        ? new Container(
//      decoration: BoxDecoration(
//          border: Border(
//              bottom: new BorderSide(
//                  color: Colors.grey, width: showShadow ? 0.5 : 0.0))),
//      child: new AppBar(
//        title: titleW == null
//            ? new Text(
//          title,
//          style: new TextStyle(
//              color: mainColor,
//              fontSize: 17.0,
//              fontWeight: FontWeight.w500),
//        )
//            : titleW,
//        backgroundColor: mainColor,
//        elevation: 0.0,
//        brightness: Brightness.dark,
//        leading: leadingW ?? leading(context),
//        centerTitle: true,
//        actions: rightDMActions ?? [new Center()],
//        bottom: bottom != null ? bottom : null,
//      ),
//    )
//        : new AppBar(
//      title: titleW == null
//          ? new Text(
//        title,
//        style: new TextStyle(
//            color: mainColor,
//            fontSize: 17.0,
//            fontWeight: FontWeight.w500),
//      )
//          : titleW,
//      backgroundColor: backgroundColor[0],
//      elevation: 0.0,
//      brightness: Brightness.dark,
//      leading: leadingW ?? leading(context),
//      centerTitle: false,
//      bottom: bottom != null ? bottom : null,
//      actions: rightDMActions ?? [new Center()],
//    );
//  }
}
